package com.hydra.base.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 字符串工具类
 * @Author Hydra
 * @Date 2022/5/5 10:36
 */
public class StringUtil extends StringUtils {

    /**下划线转驼峰，匹配下划线加任意一个字符*/
    private static final Pattern UNDER_LINE_PATTERN = Pattern.compile("_(\\w)");

    /**
     * 下换线转驼峰
     */
    public static String underLineToCamel(String source) {
        Matcher matcher = UNDER_LINE_PATTERN.matcher(source);
        StringBuffer result = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(result, matcher.group(1).toUpperCase());
        }
        matcher.appendTail(result);
        return result.toString();
    }

}
